package com.hsogoo.avatar.registry;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * Created by za-huangsaigang on 2018/10/19.
 */
public class RegistryLoader {

    public static AvatarRegistry loadDefaultRegistry(){
        ServiceLoader<AvatarRegistry> loader = ServiceLoader.load(AvatarRegistry.class);
        Iterator<AvatarRegistry> iterator = loader.iterator();
        if (!iterator.hasNext()) {
            throw new IllegalStateException(String.format(
                    "no implementation defined in /META-INF/services/%s, please check whether the file exists and has the right implementation class!",
                    AvatarRegistry.class.getName()));
        }
        return iterator.next();
    }
}
